<?php

class valuelot_shipping_config extends a_admin_controller {

    protected $vl_config;

    public function __construct($post_handling_enabled = FALSE) {
        quick_include("checkout_shipping", "vl_config", "models/vl");
        parent::__construct($post_handling_enabled);
    }

    public function index() {
        $province = "mb";
        if ($this->input->post("province")) {
            $province = $this->input->post("province");
        }
        $this->vl_config = new vl_config();
        $this->vl_config->get_by_province($province);

        if ($this->input->post("update")) {
            $this->update();
        }
    }

    protected function update() {
        if (is_numeric($this->input->post("per_item"))
                && is_numeric($this->input->post("perishable"))
                && is_numeric($this->input->post("non_perishable"))
                && is_numeric($this->input->post("non_food_item"))
                && is_numeric($this->input->post("non_food_mail"))) {
            $this->vl_config->per_item = $this->input->post("per_item");
            $this->vl_config->perishable = $this->input->post("perishable");
            $this->vl_config->non_perishable = $this->input->post("non_perishable");
            $this->vl_config->non_food_item = $this->input->post("non_food_item");
            $this->vl_config->non_food_mail = $this->input->post("non_food_mail");
            if ($this->input->post("winnipeg")) {
                $this->vl_config->winnipeg = $this->input->post("winnipeg");
            }
            $this->vl_config->save();
        }else{
            $this->add_global_msg("Invalid input detected.Could not UPDATE!");
        }
    }

    public function batch_assign() {
        if ($this->vl_config) {
            $this->assign("vl_config", $this->vl_config->convert_to_simple_data());
        }
    }

}

?>
